package net.zjitc.service.impl;

import net.zjitc.mapper.AdminMapper;
import net.zjitc.mapper.CategoryMapper;
import net.zjitc.pojo.Category;
import net.zjitc.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public List<Category> getAllCategories() {
        List<Category> categories = categoryMapper.getAllCategories();
//        for(int i=0;i<categories.size();i++){
//            Category category=categories.get(i);
//            Integer pid=category.getPid();
//            //根据pid的值，从category中找到对应的name，从categories中找
//            if(pid!=0){
//                for(Category c:categories){
//                    if(c.getId()==pid){
//                        category.setPname(c.getName());
//                    }
//                }
//            }
//        }
        return categories;
    }

    @Override
    public Category getCategoryById(String name) {
        return categoryMapper.getCategoryById(name);
    }
}
